home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************\
- **
- ** DIGNET AREXX MIDI MONITOR 1.0
- **
- **
- ** Copyright © 1997 by Digital Surface/Kenneth "Kenny" Nilsen
- ** Public domain.
- **
- **---------------------------------------------------------------------------
- **
- ** This little script will monitor the MIDI port. You should give the
- ** correct device name and unit number below to fit your system.
- **
- ** NOTE: The midi monitoring isn't accurate in this demo script. The
- ** routines must have been written differently to achive that. The
- ** intention with this script is just to show the possibilities with the
- ** dignet.library. However, the RAW logfile in RAM: should be accurate
- ** since it uses the Capture function which gets all bytes from the port
- ** saved directly to the file.
- **
- \***************************************************************************/
-
- /* Change these settings to fit your system: */
-
- DeviceName = "serial.device"
- Unit = "0"
-
- /*-------------------------------------------------------------------------*/
-
- LF = '0a'x
-
- Options RESULTS /* important or else we wount get net number
- */
- signal on Break_C
-
- SAY '0c'x
- SAY "MIDI MONITOR VERSION 1.0 - by Digital Surface/Kenneth 'Kenny' Nilsen"
- SAY "--------------------------------------------------------------------"
- SAY "This arexx script is public domain. Created 1997."
- SAY "Require 'dignet.library' version 4 or better due to the built in"
- SAY "arexx host in the library."LF
-
- IF ~show('p', 'DIGNET') then do
- address command
- "c:loadlib dignet.library"
- "WaitForPort DIGNET"
- END
-
-
- Address "DIGNET" /* arexx port of library
- --------------------------------*/
-
- AllocNet '"'devicename'"' '"'unit'"'
-
- IF (rc~=0) then do
- say "ERROR: Couldn't allocate this net! Check device name and unit.."
- exit 0
- END
-
- Net=RESULT
-
- SAY "- PRESS CTRL + C TO STOP MONITORING..."
- SAY "- Starting RAW MIDI capturing to file 'ram:MIDI.raw'"
-
- /* You should be able to send the raw file directly to a midi instrument */
-
- CaptureTextStart '"'Net'"' 0 "ram:MIDI.raw"
- IF (rc~=0) then SAY "Couldn't capture to file!"
-
- SetDefault '"'Net'"'
- IF (rc~=0) then say "Couldn't set default parameters to net!"
-
- SetBaud '"'Net'"' 31250 /* MIDI baud speed !
- */
- FlushNet '"'net'"'
- IF (rc~=0) then say "Couldn't flush the net!"
-
- SAY "--------------------------------------------------------------------"
-
- /* Here is the main loop that monitors the MIDI port */
-
- skip=0
-
- do forever
-
- Timeout '"'Net'"' 2
- bytes=result
-
- ReadNet '"'Net'"' '"'bytes'"'
- if (rc~=0) then do
- say "Error reading from MIDI port!"
- say "Quitting..."
- FreeNet '"'net'"'
- exit 0
- END
-
- if bytes=0 then skip=3
-
- buffer=result||'00'x||'00'x
- len=length(buffer)
- pos=1
-
- do until len=pos-2
-
- byte=substr(buffer,pos,1)
-
- /* check which type of byte this is */
-
- stat=c2d(byte)
-
- if stat="247" then do
- skip=0
- say "SYSTEM EXCLUSIVE END"
- end
-
- if stat="240" then skip=2
-
- if skip=2 then do
- skip=1
- id=c2d(substr(buffer,pos+1,1))
- say "SYSTEM EXCLUSIVE START (ID="ID")"
- end
-
- if skip=0 then do
-
- if stat="242" then do
- call bitclr(byte,7)
- say "SYSTEM COMMON MSG: SONG POSITION POINTER ("c2d(substr(buffer,pos+1,1))") ("c2d(substr(buffer,pos+2,1))")"
- end
-
- if stat="243" then do
- call bitclr(byte,7)
- say "SYSTEM COMMON MSG: SONG SELECT ("c2d(substr(buffer,pos+1,1))")"
- end
-
- if stat="246" then do
- call bitclr(byte,7)
- say "SYSTEM COMMON MSG: TUNE REQUEST"
- end
-
- if stat="248" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: MIDI CLOCK"
- end
-
- if stat="250" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: START"
- end
-
- if stat="251" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: CONTINUE"
- end
-
- if stat="252" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: STOP"
- end
-
- /* if stat="254" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: ACTIVE SENSING"
- END
- */
-
- if stat="255" then do
- call bitclr(byte,7)
- say "SYSTEM REAL TIME MSG: SYSTEM RESET"
- end
-
- if bittst(byte,7)=1 then do
- msg=c2d(bitand(byte,'F0'x))
- chan=c2d(bitand(byte,'0F'x))+"1"
-
- note=""
- byte=substr(buffer,pos+1,1)
- if bittst(byte,7)=0 then note=c2d(byte)
-
- data=""
- byte=substr(buffer,pos+2,1)
- if bittst(byte,7)=0 then data=c2d(byte)
-
- if msg="128" then say "CHANNEL MODE: NOTE OFF MIDICH: "chan" NOTE: "note" DATA: "data
- if msg="144" then say "CHANNEL MODE: NOTE ON MIDICH: "chan" NOTE: "note" VELOCITY: "data
- if msg="160" then say "CHANNEL MODE: POLY KEY PRESSURE MIDICH: "chan" NOTE: "note" DATA: "data
- if msg="176" then say "CHANNEL MODE: CONTROL CHANGE MIDICH: "chan" DATA: "note" DATA: "data
- if msg="192" then say "CHANNEL MODE: PROGRAM CHANGE MIDICH: "chan" DATA: "note" DATA: "data
- if msg="208" then say "CHANNEL MODE: CHANNEL PRESSURE MIDICH: "chan" NOTE: "note" DATA: "data
- if msg="224" then say "CHANNEL MODE: PITCHBEND CHANGE MIDICH: "chan" NOTE: "note" DATA: "data
-
- end
- end
-
- if skip=3 then skip=0
-
- pos=pos+1
- end
- end
-
-
- Break_C:
-
- SAY "--------------------------------------------------------------------"
- SAY "MIDI Monitor ended!"
-
- FlushNet '"'Net'"'
- FreeNet '"'Net'"' /* Enclose the net variable like this or else
- arexx will give the keyword 'net' instead
- of its contents (the netnumber)
- */
-
- IF (rc=5) then SAY "Error: Net' Net 'was not allocated!"
-
- exit 0
-